package com.scarymovieapp.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.scarymovieapp.R;
import com.scarymovieapp.dto.MovieSearch;

public class AdvancedMovieSearch extends Activity {
	
	public static final String MOVIE_SEARCH = "MOVIE_SEARCH";
	private EditText movieName;
	private Button btnSearch;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//gets access to UI components
		movieName = (EditText) findViewById(R.id.movieName);
		btnSearch = (Button) findViewById(R.id.btnSearch);
		
		//makes button work
		OnClickListener clickListener = new SearchButtonListener();
		btnSearch.setOnClickListener(clickListener);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	


   
	private void search() {
		 Toast.makeText(AdvancedMovieSearch.this, "You clicked me!", Toast.LENGTH_LONG).show();
		String movieNameText = movieName.getText().toString();
		
		//creates and fills movie search object
		MovieSearch ms = new MovieSearch();
		ms.setName(movieNameText);
		
		//activity that searches and shows results
		Intent movieResultsIntent = new Intent(this, MovieResultsActivity.class);
		
		//passes along search info to results screen
		movieResultsIntent.putExtra(MOVIE_SEARCH, ms);
		
		//place results on screen
		startActivity(movieResultsIntent);
	}
	
    class SearchButtonListener implements OnClickListener {

        @Override
        public void onClick(View v) {
                search();
        }


}
}

